﻿namespace LxCFD
{
    public class ValueStateLog
    {
        public enum ValueStates
        {
            RunOnce_Undone,
            RunOnce_Done,
            AlwaysRun,
        }
        public ValueStateLog(ValueStates valueState)
        {
            this._valueState = valueState;
        }
        public ValueStateLog(bool isConst)
        {
            if (isConst)
            {
                _valueState = ValueStates.RunOnce_Undone;
            }else
            {
                _valueState = ValueStates.AlwaysRun;
            }
        }
        public ValueStates valueState { get => _valueState; set => _valueState = value; }
        private volatile ValueStates _valueState = ValueStates.AlwaysRun;
        public void SetStateUsed()
        {
            if (_valueState == ValueStates.RunOnce_Undone)
            {
                _valueState = ValueStates.RunOnce_Done;
            }
        }
        public bool GetIsNeedToCal(int taskIndex)
        {
            switch (_valueState)
            {
                case ValueStates.RunOnce_Undone:
                    MultiThreads.Sync(taskIndex, SetStateUsed);
                    return true;
                case ValueStates.RunOnce_Done:
                    return false;
                case ValueStates.AlwaysRun:
                default:
                    return true;
            }
        }
    }
}
